<?php
class MenuAction extends Action {
	function _initialize() {
		$this->assign ( "menuFirst", session ( 'menuFirst' ) );
		$this->assign ( "menuSecond", session ( 'menuSecond' ) );
	}
	function mlist() {
		$ob = M ( "csl_menu" );
		
		$sql [] = array (
				'pid' => 0 
		);
		$list = $ob->where ( $sql )->order ( "ordid asc" )->select ();
		
		foreach ( $list as $key => $value ) {
			$list [$key] ['submenu'] = $ob->where ( array (
					'pid' => $value ['menuid'] 
			) )->order ( "ordid asc" )->select ();
		}
		
		$this->assign ( "list", $list );
		$this->display ( "Menu/mlist" );
	}
	function detail() {
		if ($_GET ['opt'] == 'add') { // 新增跳转
			$ob = M ( "csl_menu" );
			$menulist = $ob->where ( array (
					"pid" => "0",
					"display" => "1" 
			) )->select ();
			
			$this->assign ( "menulist", $menulist );
			$this->display ( "Menu/detail" );
			return;
		}
		
		if ($_GET ["opt"] == 'edit') { // 编辑
			$ob = M ( "csl_menu" );
			$info = $ob->where ( array (
					"menuid" => $_GET ["menuid"] 
			) )->find ();
			// 上级菜单
			$menulist = $ob->where ( array (
					"pid" => "0",
					"display" => "1" 
			) )->select ();
			$this->assign ( "menulist", $menulist );
			
			$this->assign ( "modify", '1' );
			$this->assign ( "info", $info );
			$this->display ( 'Menu/detail' );
			return;
		}
		
		if ($_POST) {
			// 添加
			$_POST ['adminid'] = session ( 'info.uid' );
			$_POST ['add_time'] = time (); // date('Y-m-d H:i:s', time());
			$ob = M ( "csl_menu" );
			
			if ($_POST ['menuid'] != '') {
				$ob->where ( array (
						'menuid' => $_POST ['menuid'] 
				) )->save ( $_POST );
			} else {
				$ob->add ( $_POST );
			}
			
			$this->redirect ( '/Admin/Menu/mlist/' );
			return;
		}
	}
}

?>